package com.sys.service;

import com.sys.GlobalVariable;
import com.sys.utils.DbUtil4;
import com.sys.utils.DbUtil4Factory;

import java.sql.SQLException;
import java.util.*;

public class ViewService {
    public List<Map<String, Object>> count() throws Exception{
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        List<Map<String,Object>> list1 = null;
        List<Map<String,Object>> list2 = null;
        List<Map<String,Object>> list3 = null;
        List<Map<String,Object>> list4 = null;
        List<Map<String,Object>> list5 = null;
        DbUtil4 db = null;
        boolean t = false;
        String sql4 = "SELECT commodity as 商品 FROM view_commodity";
        String sql1 = "SELECT customer as 客户 FROM view_customer";
        String sql5 = "SELECT device as 设备 FROM view_device";
        String sql2 = "SELECT trainer as 教练 FROM view_trainer";
        String sql3 = "SELECT course as 课程 FROM view_course";
        try {
            db = DbUtil4Factory.getDbUtil4(GlobalVariable.dbconfigPath, "utf-8");
            list1 = db.query(sql1, new Object[]{});
            list2 = db.query(sql2, new Object[]{});
            list3 = db.query(sql3, new Object[]{});
            list4 = db.query(sql4, new Object[]{});
            list5 = db.query(sql5, new Object[]{});
            System.out.println("list1.get(0):"+list1.get(0));
            System.out.println("list1:"+list1);
            System.out.println(list1.get(0).getClass().toString());

            list.add(list1.get(0));
            list.add(list2.get(0));
            list.add(list3.get(0));
            list.add(list4.get(0));
            list.add(list5.get(0));
        } catch (Exception e) {
                throw e;
        } finally {
            try {
                if (db != null) {
                    db.close();
                }
            } catch (SQLException e) {
                try {
                    throw e;
                } catch (SQLException ex) {
                    throw new RuntimeException(ex);
                }
            }
        }
        return list;
    }
}
